using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace EnsoNetServer
{
    public partial class ConfigurationForm : Form
    {
        #region Constructor

        public ConfigurationForm()
        {
            InitializeComponent();
        }

        #endregion

        #region Overriden Methods

        protected override void OnClosing(CancelEventArgs e)
        {
            FormClosingEventArgs a = (FormClosingEventArgs)e;

            if (a.CloseReason == CloseReason.UserClosing)
            {
                WindowState = FormWindowState.Minimized;
                ShowInTaskbar = false;

                e.Cancel = true;
            }
            else
            {
                CommandServer.UnloadAll();
            }
        }

        #endregion

        #region Event Handlers

        /// <summary>
        /// Exit the server.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Event args.</param>
        private void _cmdExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void _cmdClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void _ctlTrayIcon_DoubleClick(object sender, EventArgs e)
        {
            _lstCommandlets.Items.Clear();

            foreach (string command in CommandServer.EnumerateCommands())
                _lstCommandlets.Items.Add(command);

            ShowInTaskbar = true;

            WindowState = FormWindowState.Normal;
        }

        #endregion
    }
}